package com.zhu.char07

/**
 *
 * @version 1.0
 * @author study
 * @date 2020/9/5 21:09
 *
 */
/**
 * 集合计算高级
 */
object Scala_TestFun03 {
  def main(args: Array[String]): Unit = {
    val list: List[Int] = List(1, 2, 3, 4, 5, 6)
    //过滤
    //取出偶数放到新集合
    val value = list.filter((ele: Int) => (ele % 2 == 0))
    println(value)

    //转化
    println(list.map(_ * 2))

    //扁平化
    val newList = List(List(1, 2, 3), List(4, 5, 6), List(7, 8, 9))
    newList.flatten.foreach(println)

    val strList = List("hello scala", "hello java", "hello go")

    //扁平映射
    val value1 = strList.flatMap(_.split(" "))
    println(value1)


    //分组
    val groupList = List(1, 2, 3, 4, 5, 6, 7, 8)

    println(groupList.groupBy(_ % 2))


  }
}
